<?php
/**
 * Created by PhpStorm.
 * User: ycp
 * Date: 2019/12/29
 * Time: 11:00
 */

namespace app\api\controller\tools;



use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;

class LiteApp extends BasicWeChat
{

    /**
     * @param string $openId
     * @param array $sendData
     * @return array|bool|string
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     * @author ycp
     */
    public function subscribeMessageSend($openId = '', $sendData = [])
    {
        $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=ACCESS_TOKEN';
        $this->registerApi($url, __FUNCTION__, func_get_args());

        $params['touser'] = $openId;
        $params['template_id'] = '-ib8s8PRjp81McgQ6WJ0EGtHJn-nJ7lZuByZZv9nI-A';
        $params['page'] = "/pages/order/order?state=0";
//        $params['form_id'] = "";
        $msg = '请有疑问,请联系管理员咨询';
        $desc = isset($sendData['refuseData']) ? $sendData['refuseData'] . $msg : $msg;
        $params['data'] = [
            'thing1' => ['value' => $sendData['name']],
            'date2' => ['value' => $sendData['pay_at']],
            'phrase3' => ['value' => $sendData['res']],
            'thing4' => ['value' => $desc],
        ];
        $result = Tools::post($url, Tools::arr2json($params));
        if (json_decode($result)) {
            return Tools::json2arr($result);
        }
        return 0;
    }
}